home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / macabuse / imlib / fonts.c < prev    next >
C/C++ Source or Header  |  1997-05-20  |  2KB  |  76 lines

  1. #include "fonts.hpp"
  2. #include <ctype.h>
  3.  
  4. texture_font::texture_font(image *letters, image *font_pattern)
  5. { fntpat=font_pattern;
  6.   let=letters;
  7.   tl=(let->width()+1)/32;
  8.   th=(let->height()+1)/8;
  9. }
  10.  
  11. void texture_font::put_char(image *screen,  int x, int y, char ch)
  12. { if (fntpat)
  13.     fntpat->put_part_masked(screen,let, x,y,
  14.        ((int)ch%32)*tl,((int)ch/32)*th,0,0,tl-1,th-1);
  15.   else let->put_part(screen,x,y,((int)ch%32)*tl,((int)ch/32)*th,
  16.      ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1);
  17. }
  18.  
  19. void texture_font::put_string(image *screen, int x, int y, char *st)
  20. { while (*st)
  21.   { put_char(screen,x,y,*st);
  22.     st++;
  23.     x+=tl;
  24.   }
  25. }
  26.  
  27.  
  28. void JCFont::put_string(image *screen, int x, int y, char *st, int color)
  29. { while (*st)
  30.   { put_char(screen,x,y,*st,color);
  31.     st++;
  32.     x+=tl;
  33.   }
  34. }
  35.  
  36.  
  37. void JCFont::put_char(image *screen,  int x, int y, char ch, int color)
  38. {
  39.   if (let[(unsigned char)ch])
  40.   {
  41.     if (color>=0)
  42.       let[(unsigned char)ch]->put_color(screen,x,y,color);
  43.     else let[(unsigned char)ch]->put_image(screen,x,y);
  44.   }
  45. }
  46.  
  47. JCFont::JCFont(image *letters)
  48. {
  49.   tl=(letters->width()+1)/32;
  50.   th=(letters->height()+1)/8;    
  51.  
  52.   image tmp(tl,th);
  53.   
  54.   int ch;
  55.   
  56.   for (ch=0;ch<256;ch++)
  57.   {    
  58.     if (ch>' ' && ch<'~')
  59.     {
  60.       tmp.clear();    
  61.       letters->put_part(&tmp,0,0,((int)ch%32)*tl,((int)ch/32)*th,
  62.           ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1);  
  63.       let[ch]=new trans_image(&tmp,"JCfont");
  64.     } else let[ch]=0;
  65.   } 
  66. }
  67.  
  68. JCFont::~JCFont()
  69. {
  70.   int ch;
  71.   for (ch=0;ch<256;ch++)  
  72.     if (let[(unsigned char)ch])
  73.       delete let[(unsigned char)ch];  
  74. }
  75.  
  76.